import org.junit.Test

import scala.collection.mutable.ArrayBuffer

class test {
  @Test
  //  数组定义，输出并找最大值
  def test(): Unit = {
    val r = new Array[Int](4)
    for (i <- 0 until r.length) {
      r(i) = i + 3
    }
    var max = 0
    for (i <- 0 to 3) {
      println(r(i))
      if (max < r(i))
        max = r(i)
    }
    println("max:" + max)
  }

  @Test
  //  定义二维数组，并输出
  def test2(): Unit = {
    val myArray = Array.ofDim[Int](3, 2)
    for (i <- 0 to 2; j <- 0 to 1) {
      myArray(i)(j) = i + j
    }
    for (i <- 0 to 2; j <- 0 to 1) {
      println("myArray(" + i + ")(" + j + "):" + myArray(i)(j))
    }
  }

  @Test
  //  合并，转换可变，加值，输出
  def test3(): Unit = {
    val arr1 = Array(1, 3, 5)
    val arr2 = Array(2, 4, 6)
    val arr3 = Array.concat(arr1, arr2)

    val arr4 = ArrayBuffer[Int]()
    arr4 ++= arr3
    arr4 += 3
    for (i <- 0 until arr4.length) {
      println(arr4(i))
    }
  }

  @Test
  //  定义一个Map映射变量，首先判断此变量是否为空，如果不为空可通过key获取相应的值并打印。
  def test4(): Unit = {
    val Student = Map("01" -> "Hu", "02" -> "Li", "03" -> "Jiang")
    for (i <- Student) {
      //      i是一个元组
      if (!Map(i).isEmpty) {
        val firstName = Map(i)
        println("key:" + i._1)
        println("firstName:" + i._2)

      }
    }
  }

  @Test
  //  定义两个map变量，将这两个变量进行合并，并可将变量当中的key和值分别打印出来。
  def test5(): Unit = {
    val color1 = Map("01" -> "red", "02" -> "blue")
    val color2 = Map("01" -> "black", "03" -> "yellow")
    var colors = color1 ++ color2
    for (i <- colors if !Map(i).isEmpty) {
      println("key:" + i._1)
      println("value:" + i._2)
    }
  }

  import scala.collection.mutable.Set

  //  定义set集合，并且完成对set集合的添加、删除。并将每次操作进行打印输出。
  @Test
  def test6(): Unit = {
    val set = Set(1, 2, 3)
    println(set)
    set += 4;
    println(set)
    set -= 1
    println(set);
  }


}
